package memento
type ServerConfig struct {
	Host string
	Port int
	MaxConnections int
}

func (c *ServerConfig) CreateMemento() *Memento {
	return NewMemento(c.Host, c.Port, c.MaxConnections)
}

func (c *ServerConfig) RestoreMemento(m *Memento) {
	c.Host = m.GetHost()
	c.Port = m.GetPort()
	c.MaxConnections = m.GetMaxConnections()
}

type Memento struct {
	host  string
	port int
	maxConnections int
}

func NewMemento(host  string, port, maxConnections int) *Memento {
	return &Memento{
		host: host,
		port: port,
		maxConnections: maxConnections,
	}
}

func (m *Memento) GetHost() string {
	return m.host
}

func (m *Memento) GetPort() int {
	return m.port
}

func (m *Memento) GetMaxConnections() int {
	return m.maxConnections
}

type Caretaker struct {
	mementoList []*Memento
}

func (c *Caretaker) AddMemento(m *Memento) {
	c.mementoList = append(c.mementoList, m)
}

func (c *Caretaker) GetMemento(index int) *Memento {
	if index < 0 || index > len(c.mementoList)-1 {
		return nil
	}
	return c.mementoList[index]
}







